package net.dreamlu.qa.controller;

import net.dreamlu.qa.model.Question;
import net.dreamlu.qa.model.User;

import com.jfinal.core.Controller;
import com.jfinal.kit.StringKit;

/**
 * 问题详情
 * @author chunmeng.lu
 *
 */
public class QController extends Controller{
	
	// 根据问题id 获取
	public void index(){
		Question question = Question.dao.findById(getParaToInt()); 
		if(StringKit.notNull(question)){
			setAttr("question", question);
			// 获取用户
			setAttr("user", User.dao.findById(question.get("user_id")));
			// 获取回答
			setAttr("answersList", question.getAnswers());
			
			System.out.println(question.getAnswers().size());
			
			// 获取标签
			setAttr("tagsList", question.getTags());
			// 获取同类问题
			setAttr("sortQList", question.sortQuestionList());
			render("/solution/question.jsp");
		}else{
			render("/error/error.jsp");
		}
	}
}

